URL
Type
keyword
Summary
Designates a container consisting of an Internet resource or local file in the form of a URL.
Syntax
URL
Description
Use the URL keyword to access the contents of a local file or a file accessible on the Web.
A URL is a method of designating a file or other resource. You can use a URL like any other container. You can get the contents of a URL or use its contents in any expression. LiveCode supports the following URL schemes:
- http: a page from a < web server:::note[ ftp: a directory or file on an FTP server ]
file: a text file on the local disk (not on a server)
- binfile: a binary file
- resfile: on Mac OS and OS X systems, the resource fork of a file
:::
All actions that refer to a URL container are blocking: that is, the handler pauses until LiveCode is finished accessing the URL. Since fetching a web page may take some time due to network lag, accessing URLs may take long enough to be noticeable to the user. To avoid this delay, use the load command (which is non-blocking) to cache web pages before you need them.
For technical information about URLs and URL scheme|URL schemes, see RFC 1630.
The http, ftp and https keywords are part of the Internet library on desktop platforms. To ensure that the keywords work in a desktop standalone application, you must include this custom library when you create your standalone. In the Inclusions pane of the Standalone Application Settings window, make sure the "Internet" script library is selected.
On iOS and Android, you can use the http, ftp and https keywords without the need for the Internet library. When specifying URLs for iOS and Android, you must use the appropriate form that conforms to RFC 1630.
The space character is not valid in URLs, however the Internet library (Desktop platforms) replaces this character with the required '%20'. This is something that the mobile and server platforms do not do. Be careful to construct valid URLs when working on fully cross platform applications.
Examples
get URL "http://www.xworlds.com/index.html"
put URL "binfile:/Users/myuser/Files/example.gif" into image "Example Logo"
post field "Results" to URL "http://www.example.org/current.txt"
local tURL
put "http://www.xworlds.com/index.html" into tURL
get URL tURL
put "Hello World" into URL "file:/Users/myuser/Documents/sample.txt"
-- Writing the contents of a field to an external file, preserving text encoding
on textSave
put "всем привет" into field "russiantext"
put textEncode(field "russiantext" ,"UTF-8") into URL "binfile:/Users/myuser/Documents/russtext.txt"
end textSave
# Reading contents of a file into LiveCode, preserving text encoding
on textRead
local tText
put URL "binfile:/Users/myuser/Documents/russtext.txt" into tText
put textDecode(tText,"UTF-8") into field "russiantext"
end textRead
Related
command: launch url, libURLSetAuthCallback, libURLSetExpect100, load
function: urlEncode
glossary: binary file, command, container, expression, file, FTP, keyword, LiveCode custom library, local file, platform, resource, resource fork, server, standalone application, text file, Unicode, URL, URL scheme, web server
keyword: binfile, file, ftp, http, resfile, URL
library: Internet library
property: HTMLText
Compatibility and Support
Introduced
LiveCode 1.0
OS
mac
windows
linux
ios
android
Platforms
desktop
server
mobile